package peluqueria;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Hashtable;
import java.util.List;
import javax.swing.BorderFactory;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;

import paneles.PanelServ;
import accesoADatos.AccesoADatos;
import datos.Caja;
import datos.Servicio;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModifJDialog extends javax.swing.JDialog {
	
	
	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				ModifJDialog inst = new ModifJDialog(frame," ");
				inst.setVisible(true);
			}
		});
	}
	private Hashtable hash=new Hashtable();
	

	public ModifJDialog(JFrame peluqueria, String string) {
		super(peluqueria,string);
		initGUI();
	}
	private void initGUI() {
		try {
				{
				jPanel1 = new JPanel();
				FlowLayout jPanel1Layout = new FlowLayout();
				jPanel1Layout.setVgap(10);
				jPanel1.setLayout(jPanel1Layout);
				getContentPane().add(jPanel1, BorderLayout.NORTH);
				jPanel1.setPreferredSize(new java.awt.Dimension(330, 40));
				{	List l=AccesoADatos.getInstance().getServicios();
					ComboBoxModel jComboBox1Model = 
						new DefaultComboBoxModel(
								l.toArray());
					for (int i=0; i< l.size(); i++){
						hash.put(l.get(i).toString(),l.get(i));
					}
					jComboBox1 = new JComboBox();
					jPanel1.add(jComboBox1);
					jComboBox1.setModel(jComboBox1Model);
					
					jComboBox1.setPreferredSize(new java.awt.Dimension(200, 21));
					jComboBox1.setBackground(new java.awt.Color(255,255,255));
					jComboBox1.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
					jComboBox1.addPopupMenuListener(new PopupMenuListener() {
						public void popupMenuWillBecomeVisible(PopupMenuEvent evt) {
							//TODO add your code for jComboBox1.popupMenuWillBecomeVisible
						}
						public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {
							jComboBox1PopupMenuWillBecomeInvisible(evt);
						}
						public void popupMenuCanceled(PopupMenuEvent evt) {
							//TODO add your code for jComboBox1.popupMenuCanceled
						}
					});
				}
				{
					panelServ1 = new PanelServ();
					getContentPane().add(panelServ1, BorderLayout.CENTER);
					panelServ1.setPreferredSize(new java.awt.Dimension(333, 209));
					panelServ1.getBCancelar().addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							bCancelarMouseClicked(evt);
						}
					});
					panelServ1.getBAceptar().addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							bAceptarMouseClicked(evt);
						}
					});
				}
			}
			pack();
			Servicio s=(Servicio)this.hash.get(this.jComboBox1.getSelectedItem().toString());
			this.panelServ1.setServicio(s);
			this.setSize(340, 290);
			this.setLocationRelativeTo(null);
			this.setVisible(true);
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	private void bAceptarMouseClicked(MouseEvent evt) {
		Servicio serv=panelServ1.getServicio();
		Servicio s=(Servicio) this.hash.get(this.jComboBox1.getSelectedItem().toString());
		s.setNombre(serv.getNombre());
		s.setPrecio(serv.getPrecio());
		s.setPrecioProducto(serv.getPrecioProducto());
		s.setDescripcion(serv.getDescripcion());
		s.setTipo(serv.getTipo());
		AccesoADatos.getInstance().setObjeto(s);
		this.dispose();
	}
	
	private void bCancelarMouseClicked(MouseEvent evt) {
		this.dispose();
	}
	
	
	private void jComboBox1PopupMenuWillBecomeInvisible(PopupMenuEvent evt) {
		Servicio s=(Servicio)this.hash.get(this.jComboBox1.getSelectedItem().toString());
		this.panelServ1.setServicio(s);
	}
	private PanelServ panelServ1;
	private JPanel jPanel1;
	private JComboBox jComboBox1;

}
